﻿
using System;
using System.Data;
using System.Collections.Generic;

namespace LDSP.BRL
{
    public partial class R_EnterpriseCodification : BYFW.BOL.BaseEntity
    {
        public R_EnterpriseCodification()
        {
            m_tableName = "t_r_enterprise_codification";
            m_hasName = true;
            m_hasComment = true;
            m_tblCacheManager.IsEnable = true;
        }

        protected int m_enterpriseID = 0;
        protected int m_docID = 0;
        protected DateTime m_favoriteDT = DateTime.MinValue;

        /// <summary>
        /// 企业ID
        /// </summary>
        public int EnterpriseID
        {
            get { return m_enterpriseID; }
            set { m_enterpriseID = value; }
        }
        /// <summary>
        /// 文档ID
        /// </summary>
        public int DocID
        {
            get { return m_docID; }
            set { m_docID = value; }
        }
        /// <summary>
        /// 收藏时间
        /// </summary>
        public DateTime FavoriteDT
        {
            get { return m_favoriteDT; }
            set { m_favoriteDT = value; }
        }

        protected override void FillContainer()
        {
            base.FillContainer();
            m_container.Add("enterpriseID", m_enterpriseID);
            m_container.Add("docID", m_docID);
            m_container.Add("favoriteDT", m_favoriteDT);
        }

        public override bool GetProperties(System.Data.DataRow record)
        {
            if (!base.GetProperties(record))
            {
                return false;
            }
            m_enterpriseID = this.GetIntValue(record, "enterpriseID");
            m_docID = this.GetIntValue(record, "docID");
            m_favoriteDT = this.GetDateValue(record, "favoriteDT");
            return true;
        }

        public List<R_EnterpriseCodification> GetListByEnterpriseAndCodification(int enterpriseID, int docID)
        {
            string cond = string.Format("where {0}={1} and {2}={3}", 
                DB.GetCol("enterpriseID"), DB.GetVal(enterpriseID),
                DB.GetCol("docID"), DB.GetVal(docID));
            return this.GetSpecialList<R_EnterpriseCodification>(null, cond);
        }
        public List<R_EnterpriseCodification> GetListByCodification(int docID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("docID"), DB.GetVal(docID));
            return this.GetSpecialList<R_EnterpriseCodification>(null, cond);
        }

        public List<R_EnterpriseCodification> GetListByEnterprise(int enterpriseID)
        {
            string cond = string.Format("where {0}={1}", DB.GetCol("enterpriseID"), DB.GetVal(enterpriseID));
            return this.GetSpecialList<R_EnterpriseCodification>(null, cond);
        }

        public override int Delete(string transID)
        {
            new R_CodificationUser().DeleteByCodification(m_id);
            new Plan().DeleteByCodification(m_id);
            return base.Delete(transID);
        }
    }
}
